<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<base href="<%=basePath%>" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>合同清单</title>
		<link rel="stylesheet" href="res/layui/css/layui.css">
		<script src="res/js/jquery-2.1.4.min.js" type="text/javascript"></script>
		<script src="res/layui/layui.js"></script>
	</head>
	<body style="padding: 40px 40px 0px 40px">
		<form class="layui-form" id="Pact">
			<input type="hidden" id="pactId" name="pactId">
			<div class="layui-form-item">
				<label class="layui-form-label">供货商名称</label>
				<div class="layui-input-inline">
						<select class="select" name="applyName" id="applyName" lay-filter="apply">
						<option value="" >请选择供货商</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">合同名称</label>
				<div class="layui-input-block">
					<input type="text" id="pactTitle" name="pactTitle" lay-verify="required"
						placeholder="请输入合同名称" autocomplete="off" class="layui-input">
				</div>
			</div>
	
			<div class="layui-form-item">
				<label class="layui-form-label">合同编号</label>
				<div class="layui-input-block">
					<input type="text" id="pactNumber" name="pactNumber" lay-verify="required"
						placeholder="请输入合同编号" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">甲方名字</label>
				<div class="layui-input-block">
					<input type="text" id="partaName" name="partaName" lay-verify="required"
						placeholder="请输入甲方名字" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">乙方名字</label>
				<div class="layui-input-block">
					<input type="text" id="partbName" name="partbName" lay-verify="required"
						placeholder="请输入乙方名字" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">有效期</label>
				<div class="layui-input-block">
					<input type="text" id="pactEndtime" name="pactEndtime" lay-verify="required"
						placeholder="请输入部门性质" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-form-item layui-form-text">
				    <label class="layui-form-label">合同内容</label>
				    <div class="layui-input-block">
				      <textarea placeholder="请输入内容" class="layui-textarea" id="pactText" name="pactText"></textarea>
				    </div>
				</div>
			</div>
			<input type="hidden" id="departBy" name="departBy" value="${staff.staffName }">
			<div class="layui-input-block">
		        <button class="layui-btn" lay-submit lay-filter="demo">立即提交</button>
		        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		</form>
		
		<script type="text/javascript">
			var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
			
			var departId;
			
			$(function (){
				departId = GetQueryString("pactId");
				if(pactId!=null){
					pacteId(pactId);
				}
			});
			
			var form;
			layui.use(['form'], function() {
				form = layui.form;
				//监听提交
				form.on('submit(demo)', function(data){
					var data = $("#Pact").serialize();
					var url = "Pact/addOrUpdate.action";
					var loadIndex = layer.load();
					$.post(url, data, function(mes){
						parent.layer.msg(mes.mes);
						
						layer.close(loadIndex);//加载层关闭  
						parent.layer.close(index);
						if($("#pactId").val()!=""){
							$(".layui-laypage-skip .layui-laypage-btn",window.parent.document).click();//刷新父页面数据表格的当前页
						}else{
							parent.table.reload('pactId');
						}

					});
					return false;
				});
				
			});
			
			function pacteId(pactId){
				$.ajax({
					type: "POST",
					url: "Pact/pacteId.action",
					data: {"pactId":pactId},
					async: false,
					error: function(){
						layer.mes("发生未知错误，请稍后再试！");
					},
					success: function(obj){
						$("#pactId").val(obj.pactId);
						$("#pactTitle").val(obj.pactTitle);
						$("#applyName").val(obj.applyName);
						$("#pactNumber").val(obj.pactNumber);
						$("#partaName").val(obj.partaName);
						$("#partbName").val(obj.partbName);
						$("#pactEndtime").val(obj.pactEndtime);
					}
				});
			}
			
			var url="<%=basePath%>Pact/queryApply.action";
			$.post(url,null,function(info){
				for(i=0;i<info.length;i++){
					$("#applyName").append("<option value="+info[i].applyId+" name='applyId'>"+info[i].applyName+"</option>");
				}
			});
			
			/**
			得到URL栏的参数
			*/
			function GetQueryString(name){
			     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
			     var r = window.location.search.substr(1).match(reg);
			     if(r!=null)return  unescape(r[2]); return null;
			}
		</script>
	</body>
</html>